package org.realogic.cfm.spring;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.realogic.cfm.startup.KSystemStartupLoader;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.ModelAndView;

public class ExtDispatcherServlet extends DispatcherServlet {

	private static final long serialVersionUID = 4100164205827270670L;

	public void setContextConfigLocation(String contextConfigLocation) {
		String s = KSystemStartupLoader.initBeforeSpring(getServletContext());
		super.setContextConfigLocation(s);
	}
	
	protected void initFrameworkServlet() throws ServletException {
		KSystemStartupLoader.initAfterSpring(getServletContext(), getWebApplicationContext());
		super.initFrameworkServlet();
	}

	public void destroy() {
		KSystemStartupLoader.destroy(getServletContext());
		super.destroy();
	}

	protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac) {
		super.postProcessWebApplicationContext(wac);
	}

	protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
		return super.processHandlerException(request, response, handler, ex);
	}

}
